//
//  XCMyProjectWebViewController.m
//  SoundOfNature
//
//  Created by 梁新昌 on 16/3/23.
//  Copyright © 2016年 梁新昌. All rights reserved.
//

#import "XCMyProjectWebViewController.h"

@interface XCMyProjectWebViewController ()<UIWebViewDelegate>

@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, retain) UIActivityIndicatorView *action;
@property (nonatomic, copy) NSString *actionUrl;
@end

@implementation XCMyProjectWebViewController
- (void)dealloc {
    
    [_action release];
    [_webView release];
    [super dealloc];
}
- (instancetype)initWithActionUrl:(NSString *)actionUrl
{
    self = [super init];
    if (self) {
        self.actionUrl = actionUrl;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.webView = [[UIWebView alloc] initWithFrame:self.view.frame];
    self.webView.delegate = self;
    [self.view addSubview:self.webView];
    [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.actionUrl]]];
    
    self.navigationItem.title = @"本地专题";
    
    [_webView release];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"Image-leftBarButton"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction)];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
    UIView *view = [[UIView alloc] initWithFrame:self.view.frame];
    [view setTag:1000];
    view.alpha = 0.5;
    self.action = [[UIActivityIndicatorView alloc] initWithFrame:self.view.frame];
    [self.action setCenter:view.center];
    [self.action setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [self.view addSubview:view];
    [view addSubview:self.action];
    [self.action startAnimating];
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.action stopAnimating];
    UIView *view = (UIView *)[self.view viewWithTag:1000];
    [view removeFromSuperview];
}
- (void)leftBarButtonItemAction {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
